<?php
    // 7/13/2012: tunv rewrite this code
    class bannermediamodule {
        function name() { return "Banner Media Module"; }
        function description() { return "Banner Media Module"; }
        function author() { return "ABSoft.vn"; }

        function hasSources() { return true; }
        function hasContent() { return true; }
        function hasViews() { return true; }

        function supportsWorkflow() { return false; }
        function resizeYoutubeEmbeddedVideo($embedCode, $width, $height) 
        {
            $patterns = array();
            $patterns[0] = '/width="(.*?)"/';
            $patterns[1] = '/height="(.*?)"/';
            $replacements = array();
            $replacements[0] = 'width="' . $width . '"';
            $replacements[1] = 'height="' . $height . '"';
            return preg_replace($patterns, $replacements, $embedCode);
        }
        function permissions($internal = "") 
        {
            return array(
                'administrate'=>'Administrate',
                'configure'=>'Configure',
                'create'=>'Create Links',
                'edit'=>'Edit Links',
                'delete'=>'Delete Links'
            );
        }

        function show($view,$loc = null, $title = "") {
            global $db;
            $data = $db->selectObjects('bannermediamodule_item',$where);
            if($data)
            {
                $config = $db->selectObject('bannermediamodule_config',"location_data='".serialize($loc)."'");
            }
            foreach($data as $k=>$v)
            {
                if($v->item_type==1)
                {
                    $path = $db->selectObject("file","id = {$v->file_id}");
                    $path_full = "{$path->directory}/{$path->filename}";   
                    $v->img =  $path_full;
                }
                if(($v->item_type==2)||($v->item_type==3))
                {
                   $v->item_content = bannermediamodule::resizeYoutubeEmbeddedVideo($v->item_content,$config->iwidth,$config->iheight); 
                }
            }
            $text_src = $loc->src.'_'.LANG;
            $template = new template('bannermediamodule',$view,$loc);
            $template->register_permissions(array('administrate','configure','create','edit','delete'),$loc);
            $template->assign('data',$data);
            $template->assign('text_src',$text_src);
            $template->assign('config',$config);
            $template->output();
        }

        function deleteIn($loc) 
        {
            global $db;
        }

        function copyContent($oloc,$nloc) 
        {
        }

        function searchName() 
        {
            
        }
        function spiderTemplate($album)
        {
           
        }
        function spiderContent($item = null) {
            global $db;
            return true;
        }
    }

?>
